let mongoose = require('./db');

let Schema = mongoose.Schema;
let model = mongoose.model;

let UsersSchema = new Schema({
    userName: String,//用户名
    passWord: String,//用户密码
    create_At: {
        type: Date,
        default:  Date.now(),
    },//创建时间
    email: String,//用户邮箱
    userImg: String,//用户头像
});


let BooksSchema = new Schema({
    title: String,//书名
    author: String,//作者
    coverImage: String,//封面图像 URL
    description: String,//图书描述
    categoryId: String, //图书类别 ID，外键
    categoryName: String,//图书类型，外键
});

let CategoriesSchema = new Schema({
    categoryName: String,//分类名称
});

let FavoritesSchema = new Schema({
    userId: String,//用户 ID，外键
    bookId: String,//图书 ID，外键
    createdAt: {
        type: Date,
        default: Date.now(),
    },//创建时间
});



//胡旭博
const userSchema = new mongoose.Schema({
    username: String,
    password: String,
    phone: String,
    state: Boolean,
})

let UsersModel = model('Users', UsersSchema, 'Users');
let BooksModel = model('Books', BooksSchema, 'Books');
let CategoriesModel = model('Cate', CategoriesSchema, 'Cate');
let FavoritesModel = model('Favorites', FavoritesSchema, 'Favorites');

const userModel = mongoose.model('user', userSchema, 'user')

module.exports = { UsersModel, BooksModel, CategoriesModel, FavoritesModel,userModel };